package com.netty.netty;

import java.io.IOException;
import java.net.Socket;

/**
 * @Author: CaiXiang
 * @Date: 2019/5/23 13:38
 * @Version 1.0
 * @Description:
 */
public class Client {
    private static final String HOST = "127.0.0.1";
    private static final int PORT = 8080;
    private static final int SLEEP_TIME = 5000;

    public static void main(String[] args) throws IOException {
        final Socket socket = new Socket(HOST,PORT);
        new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("客户端启动成功");
                while (true){
                    try {
                        String message = "hello word";
                        System.out.println("客户端发送数据："+message);
                        socket.getOutputStream().write(message.getBytes());
                    }catch (IOException e){
                        System.out.println("写入数据错误");
                    }
                    sleep();
                }
            }
        }).start();
    }
    private static void sleep(){
        try {
            Thread.sleep(SLEEP_TIME);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
    }
}
